// routes/postRoutes.js
const express = require('express');
const router = express.Router();
const {
  createPost,
  getAllPosts,
  getPostById,
  updatePost,
  deletePost,
} = require('../controllers/postController');
const { protect } = require('../middleware/authMiddleware');

router.route('/')
  .post(protect, createPost) // 创建需要登录
  .get(getAllPosts);         // 查看列表是公开的

router.route('/:id')
  .get(getPostById)          // 查看单篇是公开的
  .put(protect, updatePost)  // 更新需要登录
  .delete(protect, deletePost); // 删除需要登录

module.exports = router;